'use strict';

module.exports = app => {
  const DataTypes = app.Sequelize;
  const sequelize = app.model;
  const attributes = {
    id: {
      type: DataTypes.INTEGER(10).UNSIGNED,
      allowNull: false,
      defaultValue: null,
      primaryKey: true,
      autoIncrement: true,
      comment: null,
      field: "id"
    },
    name: {
      type: DataTypes.STRING(63),
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "书名",
      field: "name"
    },
    display_type: {
      type: DataTypes.STRING(15),
      allowNull: true,
      defaultValue: "md",
      primaryKey: false,
      autoIncrement: false,
      comment: "展示的类型",
      field: "display_type"
    },
    css_url: {
      type: DataTypes.STRING(127),
      allowNull: true,
      defaultValue: "",
      primaryKey: false,
      autoIncrement: false,
      comment: "css的链接",
      field: "css_url"
    },
    cover_url: {
      type: DataTypes.STRING(127),
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "封面",
      field: "cover_url"
    },
    create_time: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
      primaryKey: false,
      autoIncrement: false,
      comment: null,
      field: "create_time"
    },
    update_time: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
      primaryKey: false,
      autoIncrement: false,
      comment: null,
      field: "update_time"
    },
    status: {
      type: DataTypes.ENUM('0', '1'),
      allowNull: false,
      defaultValue: "1",
      primaryKey: false,
      autoIncrement: false,
      comment: null,
      field: "status"
    }
  };
  const options = {
    tableName: "booklet",
    comment: "",
    indexes: [],
    createdAt: "create_time",
    updatedAt: "update_time",
  };
  const BookletModel = sequelize.define("booklet_model", attributes, options);

  BookletModel.associate = function() {
    app.model.Booklet.hasMany(
      app.model.UserBooklet,
      { foreignKey: "booklet_id" }
    )
  }

  return BookletModel;
};